package br.com.dataphonebr;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import br.com.dataphonebr.adapter.AppointmentAdapter;
import br.com.dataphonebr.adapter.NotificationListAdapter;
import br.com.dataphonebr.entity.Atividade;
import br.com.dataphonebr.service.AtividadeService;
import br.com.dataphonebr.util.AlarmUtil;

public class NotificationListActivity extends GenericActivity<Atividade> {
	
	private AtividadeService atividadeService;
	private AlarmUtil alarmUtil;
	private NotificationListAdapter notifyListener = new NotificationListAdapter(this);

	
	public NotificationListActivity() {
		super(Atividade.class);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		alarmUtil = new AlarmUtil(this);
		setContentView(R.layout.activity_notification_list);
		this.init();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
//	    inflater.inflate(R.menu.notification_list, menu);
		getActionBar().setDisplayHomeAsUpEnabled(true);
	    return true;
	} 	
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
	    case android.R.id.home:
			openView(NotificationListActivity.this, NotificationViewActivity.class, true);
	    	return true;
	    default:
	        return super.onOptionsItemSelected(item);
	    }
	}
	
	@Override
	public void init(){
		atividadeService = new AtividadeService(this);
		setServiceInstance(atividadeService);
		super.init();
	}
	
	@Override
	public void prepareList() {
//		notifyListener.createAdapter(alarmUtil.getAtividadesNotificadas(), lista);
//		if (lista != null){
//			for(int i=0; i < notifyListener.getGroupCount(); i++)
//			    lista.expandGroup(i);
//		}
//		if (lista != null){
//			lista.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener()
//			{
//				@Override
//				public boolean onGroupClick(ExpandableListView arg0, View itemView, int itemPosition, long itemId)
//				{
//					arg0.expandGroup(itemPosition);
//					return true;
//				}
//				
//			});
//		}
	}
	
	@Override
	public void prepareComponents(){
//		lista = (ExpandableListView) findViewById(R.id.resultNotifyExpListView);
		setListView(newListView(R.id.resultNotifyListView));
		adapter = new AppointmentAdapter(alarmUtil.getAtividadesNotificadas());
		getListView().setAdapter(adapter);
	}

}
